/* $RCSFile: IframeModule.ascx.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/AddonNice/PageModules/IframeModule/IframeModule.ascx.cs $
 * $log$
 * Revision 20 2010/08/09 10:51:21  christian.surieux
 *   Added Log comment to all .aspx .ascx .master files
 * Revision 19 2010/08/09 09:43:55  christian.surieux
 *   Added Log to cs sources files
 * Revision 6 2010/08/06 19:56:25  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using AddonNice.UI;
using AddonNice.UI.WebControls;
using AddonNice.UI.DataTypes;
using AddonNice.Configuration;
using AddonNice.Configuration.Settings;
using AddonNice.Helpers;
using AddonNice.Settings;
using AddonNice.Diagnostics;

using Trace2    =   System.Diagnostics.Trace;

namespace AddonNice.PageModules.IframeModule
{
    /// <summary>
    /// Initializer class for IframeModule 
    /// </summary>
    public class IframeModuleSI : PortalModuleControlSI
    {
        public IframeModuleSI(ModuleSettingsDictionary bSettings,ISettingsOwner pm) : base()
        {
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]IframeModuleSI Ctor BEG.",ModuleTraceSwitch.Sw.Info);
            InitSettings(bSettings,pm);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]IframeModuleSI Ctor END.",ModuleTraceSwitch.Sw.Info);
        }
 
        public override void InitSettings(ModuleSettingsDictionary bSettings,ISettingsOwner pm)
        {             
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]IframeModuleSI InitSettings BEG.",ModuleTraceSwitch.Sw.Info);
            
            base.InitSettings(bSettings,pm);

            string extgrp                   =   pm.ExtendedResourcesGroup;

			SettingItemSpecial url          =   new SettingItemSpecial("IFRAME_URL",new StringDataType());
			url.Required                    =   true;
            url.ExtendedGroupName           =   extgrp;
			url.Order                       =   20;
			url.Value                       =   "http://www.addonnice.com";
			bSettings.AddSetting(url);

			SettingItemSpecial width        =   new SettingItemSpecial("IFRAME_WIDTH",new StringDataType());
			width.Required                  =   true;
			width.ExtendedGroupName         =   extgrp;
			width.Order                     =   25; 
			width.Value                     =   "250px";
			bSettings.AddSetting(width);

			SettingItemSpecial height       =   new SettingItemSpecial("IFRAME_HEIGHT",new StringDataType());
			height.Required                 =   true;
			height.ExtendedGroupName        =   extgrp;
			height.Order                    =   30;
			height.Value                    =   "250px";
            bSettings.AddSetting(height);

			SettingItemSpecial border       =   new SettingItemSpecial("IFRAME_BORDER",new BooleanDataType());
			border.ExtendedGroupName        =   extgrp;
			border.Order                    =   40;
			border.Value                    =   StStr.strFalse;
            bSettings.AddSetting(border);

			SettingItemSpecial align       =   new SettingItemSpecial("IFRAME_ALIGN",new ListDataType("left;right;center"));
			align.Required                 =   true;
			align.ExtendedGroupName        =   extgrp;
			align.Order                    =   50;
			align.Value                    =   "left";
            bSettings.AddSetting(align);

            SettingItemSpecial scrolling       =   new SettingItemSpecial("IFRAME_SCROLLING",new BooleanDataType());
			scrolling.Required                 =   false;
			scrolling.ExtendedGroupName        =   extgrp;
			scrolling.Order                    =   60;
			scrolling.Value                    =   StStr.strFalse;
            bSettings.AddSetting(scrolling);
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]IframeModuleSI InitSettings END.",ModuleTraceSwitch.Sw.Info);
        }
    }

    public partial class IframeModule : PortalModuleControl
	{

		public override Guid GuidID 
		{
			get
			{
				return new Guid("{2502DB18-B580-4F90-8CB4-C15E6E531005}");
			}
		}

		
		public IframeModule() 
		{
            if ( ModuleTraceSwitch.Sw.TraceVerbose )
                Trace2.WriteLine( "[V]IframeModule Ctor Called.",ModuleTraceSwitch.Sw.Info);
        }

        public override string ExtendedResourcesGroup 
		{
            get
            {
                const string extgrp             =   "IFRAME";
                return extgrp;
            }
		}

        public override void InitPortalModuleControl(ModuleSettingsDictionary bSettings)
        {
            PortalModuleInitializer =   new IframeModuleSI(bSettings,this);
        }

        protected void Page_Load(object sender, System.EventArgs e)
		{
			string strURL       =   Settings["IFRAME_URL"].ToString();
			string height       =   Settings["IFRAME_HEIGHT"].ToString();
			string width        =   Settings["IFRAME_WIDTH"].ToString();
			bool border         =   Settings["IFRAME_BORDER"].ToBool();
			string align        =   Settings["IFRAME_ALIGN"].ToString();
			bool scrolling      =   Settings["IFRAME_SCROLLING"].ToBool();
			StringBuilder sb    =   new StringBuilder();
			sb.Append("<iframe");
			sb.AppendFormat(" src='{0}' class='AddoNiceIFrame'",strURL);
			sb.AppendFormat(" width='{0}'",width);
			sb.AppendFormat(" height='{0}'",height);
			sb.AppendFormat(" frameborder='{0}'",border ? "1":"0");
			sb.AppendFormat(" align='{0}'",align);
            if ( !scrolling )
    			sb.Append(" scrolling='no'");
    		else sb.Append(" scrolling='auto'");
			sb.AppendFormat(" title='{0}'></iframe>",TitleText);

			LiteralIframe.Text = sb.ToString();
		}

        #region Std Overrides

        override protected void OnInit(EventArgs e)
		{
			InitializeComponent();
		
			base.OnInit(e);
		}
		
		private void InitializeComponent()
		{
            Load    +=  new EventHandler(Page_Load);
		}
		#endregion
	}
}
